<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var people = `{
    "name":"张三",
    "sex":"男",
    "age":12,
    "son":{
      "name":"小明",
      "age":12
    }
  }`
    console.log(people);
    console.log('----------------');
    var p = JSON.parse(people)
    for (key in p) {
      console.log(p[key]);

      if (Array.isArray(p[key])) {
        p[key].forEach(element => {
          console.log(element);
        });
      }
    }
    console.log('----------------');

    console.log(p);
  </script>
</body>

</html>